import { UI_Listen, UI_Layer, RedDot_Key } from '../../config/ui_def'
import { SHOW_ITEM_TYPE } from '../../config/mod_def';
import { WX_AD_CONFIG, Sdk_Platform, VIVO_AD_CONFIG, OPPO_AD_CONFIG, Ad_Type } from '../../frame/constants';
import { TeamOrder } from '../../config/play_def'
import util from '../tool/util';

cc.Class({
    extends: cc.Component,

    properties: {
        // equip_pageView: cc.PageView,
        materialGrp_node: cc.Node,   //升级装备所需素材的content节点
        funcBtn_node: cc.Node,
        pageView_node: cc.Node,
        pageView_content: cc.Node,
        setEquipBtn_node: cc.Node,
        setEquipBtn_lab: cc.Label,
        lvupPanal_node: cc.Node,
        lvupBtn_node: cc.Node,
        del_node: cc.Node,
        mergeGrp: cc.Node,
        lookAd: cc.Node,
        lvupBtn_sp: cc.Sprite,
        bottomNode: cc.Node,
        fight_node: cc.Node,
        funcBtn_lab: cc.Label,
        detail_btn: cc.Node,
        num1_sp: cc.Sprite,
        num2_sp: cc.Sprite,

    },
    initPage() {
        let addNum = 4 - this.mergeGrp.childrenCount
        let reward_prefab = he.load.get("uimod/bagItem")
        for (let i = 0; i < addNum; i++) {
            let reward_node = cc.instantiate(reward_prefab)
            this.mergeGrp.addChild(reward_node)
        }

        let xxNum = 3 - this.pageView_content.childrenCount
        let pageitem = he.load.get("uimod/equipPageItem")
        for (let j = 0; j < xxNum; j++) {
            let nodje = cc.instantiate(pageitem)
            nodje.setName(`equipPageItem${j}`)
            this.pageView_content.addChild(nodje)
        }

        let fight = 5 - this.fight_node.childrenCount
        let preName = he.load.get("uimod/inFight")
        for (let k = 0; k < fight; k++) {
            let pre = cc.instantiate(preName)
            pre.name = pre.name + k
            this.fight_node.addChild(pre)
        }

        // this.mainEquip = this.node.getChildByName('mainEquip')
        // this.mE_title_lab = this.mainEquip.getChildByName('title').getComponent(cc.Label)
        // this.mE_skill_lab = this.mainEquip.getChildByName('skill').getComponent(cc.Label)
        // this.mE_detail_lab = this.mainEquip.getChildByName('detail').getComponent(cc.Label)
    },
    //
    updatePage(param) {
        this.fightIndex = 2
        gg.eventManager.on('equip', this.listenClient, this)
        this.team = he.local.getJson('team', 'user')
        this.pageViewScript = this.pageView_node.getComponent('equipPageView')
        this.pageViewScript.touchListen()
        this.equopIndex = 0
        this.index = 0
        this.info = { id: 1001 }

        this.adSwitch(true)
        this.fightInit()
        this.fightIndex = 2
        this.fight_node.children[this.fightIndex].getComponent('roleInFight').clickServer()
        for (let i = (this.pageView_content.children.length); i > 0; i--) {
            this.pageView_content.children[i - 1].getComponent('equipPageItem').clear()
            // he.pool.putElement('equipPageItem', this.pageView_content.children[i - 1])
        }
        if (param.index >= 0) {
            this.initPageView(param.index)
        } else {
            this.initPageView(0)
        }
        // this.initPageView(0)
        // this.setEquipBtn_node.active = false
        // this.hidePanal()
        if (!common.comicGuide) {
            return
        }

        // let guideList = he.local.getJson('guideList', 'user')
        // if (!guideList) {
        //     return
        // } else {
        //     if (!guideList[1]) {
        //         //新手引导
        //         guideList[1] = 1
        //         gg.data.pause = true
        //         gg.eventManager.emit('newGuide', { index: 2 })
        //         he.local.setJson('guideList', guideList, 'user')
        //     } 
        // }
    },

    fightInit() {
        let grp = []
        for (let i = 0; i < this.team.length; i++) {
            if (this.team[i].order != -1) {
                let index = this.getIndex(this.team[i].order)
                grp.push(index)
                let script = this.fight_node.children[index].getComponent('roleInFight')
                script.init(this.team[i], index)
            }
        }
        let numGrp = [0, 1, 2, 3, 4]
        let diff = this.getArrDifference(grp, numGrp)
        for (let j = 0; j < diff.length; j++) {
            let script = this.fight_node.children[diff[j]].getComponent('roleInFight')
            script.init(null, diff[j])
        }
    },
    getArrDifference(arr1, arr2) {
        return arr1.concat(arr2).filter(function (v, i, arr) {
            return arr.indexOf(v) === arr.lastIndexOf(v);
        });
    },

    getIndex(num) {
        for (let i = 0; i < TeamOrder.length; i++) {
            if (TeamOrder[i] == num) {
                return i
            }
        }
    },

    adSwitch(status) {
        if (status) {
            let guideList1 = he.local.getJson('guideList', 'user')
            if (!guideList1) {
                return
            }
            if (!guideList1[6]) {
                return
            }
            switch (common.sdk_env) {
                case Sdk_Platform.WECHAT:
                    if (!common.showAd) return
                    he.ad.getTdAdJson(WX_AD_CONFIG.tmIcon[9], this.bottomSet.bind(this))
                    break
                case Sdk_Platform.VIVO:
                    let num3 = Math.ceil(Math.random() * 10)//20 的几率弹出
                    if (num3 < 2) {
                        gg.uiManager.addPage(UI_Layer.Click, {
                            name: 'randomCardPage',
                            cover: true,
                        })
                        break
                    }
                    break
                case Sdk_Platform.OPPO:
                    gg.uiManager.addPage(UI_Layer.Msg, {
                        name: 'chayeAdFakeOPPO',
                        isShowAd: true,
                        isShowBanner: false,
                        adIndex: 5,
                        position: cc.Vec2(0, -470)
                    })
                    let num = Math.ceil(Math.random() * 10)//20 的几率弹出
                    if (num < 2) {
                        gg.uiManager.addPage(UI_Layer.Click, {
                            name: 'randomCardPage',
                            cover: true,
                        })
                        break
                    }
                    break
                case Sdk_Platform.UC:
                    let num5 = Math.ceil(Math.random() * 10)//20 的几率弹出
                    if (num5 < 2) {
                        gg.uiManager.addPage(UI_Layer.Click, {
                            name: 'randomCardPage',
                            cover: true,
                        })
                        break
                    }
                    this.ucRandom()
                    break
                case Sdk_Platform.HUAWEI:
                    gg.uiManager.addPage(UI_Layer.Msg, {
                        name: 'hwAdPage',
                        cover: false,
                        isShowAd: true,
                        adType: Ad_Type.INSERT,
                        position: 0
                    })
                    break
                default:
                    let num2 = Math.ceil(Math.random() * 10)//20 的几率弹出
                    if (num2 < 2) {
                        gg.uiManager.addPage(UI_Layer.Click, {
                            name: 'randomCardPage',
                            cover: true,
                        })
                        break
                    }
                    break
            }
        } else {
            //  关掉广告
            switch (common.sdk_env) {
                case Sdk_Platform.WECHAT:
                    break
                case Sdk_Platform.VIVO:
                    // this.bottomNode.name = VIVO_AD_CONFIG.bannerId[0]
                    // he.ad.changeBanner(status, this.bottomNode)
                    // he.ad.interstitialShow()
                    break
                case Sdk_Platform.OPPO:
                    gg.uiManager.closePage(UI_Layer.Msg, 'chayeAdFakeOPPO')
                    // this.bottomNode.name = OPPO_AD_CONFIG.bannerId[5]
                    // he.ad.changeBanner(status, this.bottomNode)
                    break
                case Sdk_Platform.UC:
                    he.ad.closeBanner()
                    break
                case Sdk_Platform.HUAWEI:
                    if (gg.uiManager.getPage(UI_Layer.Msg, 'hwAdPage')) {
                        gg.uiManager.closePage(UI_Layer.Msg, 'hwAdPage')
                    }
                    break
            }
        }
    },

    ucRandom() {
        let num5 = Math.ceil(Math.random() * 10)
        if (num5 < 5) {
            // he.ad.showBanner()
        } else {
            he.ad.showInterstitialAd()
        }
    },

    bottomSet(config) {
        if (config.isOpen) {
            let pre = he.pool.getElement('scrollAd')
            pre.parent = this.bottomNode
            pre.getComponent('scrollAd').init(config.creatives, 1, true)
        }
    },



    closeUI() {
        this.node.targetOff(this)
        this.adSwitch(false)
        this.pageViewScript.closeListen()
        if (this.mETween) {
            this.mETween.stop()
            this.mETween = null
        }
        for (let i = (this.bottomNode.children.length); i > 0; i--) {
            this.bottomNode.children[i - 1].getComponent('scrollAd').clearItem()
        }
    },

    closeServer() {
        this.uiBase.closePage()
        gg.uiManager.addPage(UI_Layer.Cover, {
            name: 'rolePage',
            // name: 'equipmentPage',
        })
        for (let j = (this.bottomNode.children.length); j > 0; j--) {
            this.bottomNode.children[j - 1].getComponent('scrollAd').clearItem()
            he.pool.putElement('scrollAd', this.bottomNode.children[j - 1])
        }
    },

    listenClient(code) {
        switch (code.type) {
            case UI_Listen.EQUIP_PAGE:
                // this.equipGrpUpdate(code.info)
                // this.setEquipBtn_node.active = false
                // this.info.id = code.info
                // console.log(this.info)
                this.pageIndex = code.info
                this.info = null
                for (let i = 0; i < this.team.length; i++) {
                    if (this.team[i].id == code.info) {
                        this.info = this.team[i]
                        break
                    }
                }

                // let passLen = he.local.getJson('pass_list', 'user').length
                // let secRole = he.local.getJson('secondRole', 'user')
                this.isLock = true

                this.isLock = !this.checkInTeam(code.info)
                if (this.isLock) {
                    // this.mainEquip.active = false
                    this.lockState()
                } else {
                    this.unlockState()
                }
                this.fight_node.children[this.fightIndex].getComponent('roleInFight').clickServer()
                this.checkState()
                break
            case UI_Listen.EQUIP_CHOOSE:
                // this.btnStateChange(code.info, code.index)
                if (code.index >= 0) {
                    this.index = code.index
                }
                this.adSwitch(false)
                gg.uiManager.closePage(UI_Layer.Msg, 'chayeAdFake')
                gg.uiManager.addPage(UI_Layer.Cover, {
                    name: 'equipDetailPage',
                    cover: true,
                    close: true,
                    info: code.info,
                    index: code.index
                })
                this.saveEquip = { info: code.info, index: code.index }
                gg.eventManager.emit('main', { type: UI_Listen.MAIN_NEWPAGE, pageName: 'equipDetail' })

                break
            case UI_Listen.EQUIP_INDEX:
                if (code.index) {
                    this.fightIndex = code.index
                }
                this.chooseItem(code.info, code.index)
                break
            case UI_Listen.EQUIP_SETEQUIP:
                this.setEquip()
                break
            case UI_Listen.EQUIP_LVUPBTN:
                gg.redManager.updateRedDot(RedDot_Key.ROLE_INFO)
                gg.redManager.updateRedDot(RedDot_Key.TASK)
                this.team = he.local.getJson('team', 'user')
                // this.initPageView(code.index)
                let info = this.team[code.index]
                gg.eventManager.emit('equipItem', { code: UI_Listen.EQUIPITEM_INFOUPDATE, info: info })
                break
            case UI_Listen.EQUIP_CLCIKBTN:
                this.funcBtnServer()
                // this.initPageView(code.index)
                break
            case UI_Listen.EQUIP_LOOKAD:
                this.lookAdServer()
                break
            case UI_Listen.EQUIP_DETAILUPDATE:
                gg.uiManager.closePage(UI_Layer.Cover, 'equipDetailPage')
                gg.uiManager.addPage(UI_Layer.Cover, {
                    name: 'equipDetailPage',
                    cover: true,
                    close: true,
                    info: this.saveEquip.info,
                    index: this.saveEquip.index
                })
                break
        }
    },

    mEUpdate() {
        this.mainEquip.active = true
        let mETween = cc.tween(this.mainEquip)
            .to(0.15, { scale: 0.8, opacity: 150 })
            .to(0.15, { scale: 1, opacity: 255 }, { easing: `elasticOut` })
            .start()
        let equipInfo = he.db.getDataByArgs('Equip', { equip: this.info.hand, level: this.info.equips[this.info.hand] })
        this.mE_title_lab.string = `${equipInfo.name} lv.${equipInfo.level}`
        this.mE_skill_lab.string = `${equipInfo.text}`
        this.mE_detail_lab.string = `+${equipInfo.attack} 攻击伤害\n+${equipInfo.attackSpeed} 攻击速度`
    },


    chooseItem(info, index) {
        this.smallItemIndex = index
        this.smallItemInfo = info
        this.chooseFightItem(index)
        this.checkState()
    },

    checkState() {
        if (this.isLock) {
            this.stage = UI_Listen.EQUIP_NONE
        } else {
            // let itemOrder = TeamOrder[this.smallItemIndex]
            if (this.smallItemInfo != null && this.smallItemInfo.order == this.info.order) {
                this.stage = UI_Listen.EQUIP_CHEXIA
            } else if (this.smallItemInfo != null && this.smallItemInfo.order != this.info.order) {
                this.stage = UI_Listen.EQUIP_TIHUAN
            }
            else if (this.smallItemInfo == null && this.info.order) {
                this.stage = UI_Listen.EQUIP_SHANGCHANG
            }
        }
        gg.eventManager.emit('equipItem', { code: UI_Listen.EQUIPITEM_GETCLICK, state: this.stage })
        // this.changeFuncBtn()
    },

    changeFuncBtn() {
        switch (this.stage) {
            case UI_Listen.EQUIP_NONE:
                this.funcBtn_node.active = false
                this.funcBtn_lab.string = null
                break
            case UI_Listen.EQUIP_SHANGCHANG:
                this.funcBtn_node.active = true
                this.funcBtn_lab.string = '上场'
                break
            case UI_Listen.EQUIP_TIHUAN:
                this.funcBtn_node.active = true
                this.funcBtn_lab.string = '替换'
                break
            case UI_Listen.EQUIP_CHEXIA:
                this.funcBtn_node.active = true
                this.funcBtn_lab.string = '撤下'
                break
        }
    },

    funcBtnServer() {
        // console.log('shoudaol   xiaoxi')
        let order = TeamOrder[this.smallItemIndex]
        switch (this.stage) {
            case UI_Listen.EQUIP_NONE:
                break
            case UI_Listen.EQUIP_SHANGCHANG:
                for (let i = 0; i < this.team.length; i++) {
                    if (this.team[i].id == this.info.id) {
                        this.team[i].order = order
                        this.info = this.team[i]
                        break
                    }
                }

                he.local.setJson('team', this.team, 'user')
                this.fightInit()
                this.fight_node.children[this.smallItemIndex].getComponent('roleInFight').clickServer()
                break
            case UI_Listen.EQUIP_TIHUAN:
                for (let a = 0; a < this.team.length; a++) {
                    if (this.team[a].id == this.smallItemInfo.id) {
                        this.team[a].order = -1
                    }
                    if (this.team[a].id == this.info.id) {
                        this.team[a].order = order
                        this.info = this.team[a]
                    }
                }
                he.local.setJson('team', this.team, 'user')
                this.fightInit()
                this.fight_node.children[this.smallItemIndex].getComponent('roleInFight').clickServer()
                break
            case UI_Listen.EQUIP_CHEXIA:
                // let order = TeamOrder[this.smallItemIndex]
                for (let j = 0; j < this.team.length; j++) {
                    if (this.team[j].id == this.info.id) {
                        this.team[j].order = -1
                        this.info = this.team[j]
                        break
                    }
                }
                he.local.setJson('team', this.team, 'user')
                this.fightInit()
                this.fight_node.children[this.smallItemIndex].getComponent('roleInFight').clickServer()
                break
        }
        // this.initPageView(0)
    },

    chooseFightItem(index) {
        // let index
        // for (let i = 0; i < TeamOrder.length; i++) {
        //     if (TeamOrder[i] == order) {
        //         index = i
        //     }
        // }
        this.hideAllFightItem()
        this.fight_node.children[index].getComponent('roleInFight').showLight()
    },
    hideAllFightItem() {
        for (let j = 0; j < this.fight_node.children.length; j++) {
            this.fight_node.children[j].getComponent('roleInFight').hideLight()
        }
    },

    checkInTeam(num) {
        let teamGrp = he.local.getJson('team', 'user')
        for (let i = 0; i < teamGrp.length; i++) {
            if (teamGrp[i].id == num) {
                return true
            }
        }
        return false
    },


    //看广告按钮
    lookAdServer() {
        switch (common.sdk_env) {
            case Sdk_Platform.WECHAT:
                util.adFakeTip()
                he.ad.showVideo(() => {
                    this.getNewRoleSec()
                    this.adAdd()
                })
                break
            case Sdk_Platform.VIVO:

                he.ad.showVideo(() => {
                    he.local.click(`vivo_video_equipPage`)
                    this.getNewRoleSec()
                    this.adAdd()
                })

                break
            case Sdk_Platform.OPPO:
                he.ad.showVideo(OPPO_AD_CONFIG.videoId[2], () => {
                    this.getNewRoleSec()
                    this.adAdd()
                })
                break
            case Sdk_Platform.UC:
                he.ad.showVideo(() => {
                    this.getNewRoleSec()
                    this.adAdd()
                })
                break
            case Sdk_Platform.HUAWEI:
                he.ad.showVideo(() => {
                    this.getNewRoleSec()
                    this.adAdd()
                })
                break
            default:
                this.getNewRoleSec()
                this.adAdd()
                break
        }
    },

    adAdd() {
        let taskGrp = he.local.getJson('task', 'user')
        if (taskGrp && taskGrp.length > 0) {
            for (let j = 0; j < taskGrp.length; j++) {
                if (taskGrp[j].type == 9001) {
                    if (taskGrp[j].num < taskGrp[j].need) {
                        taskGrp[j].num += 1
                    }
                    break
                }
            }
        }
        he.local.setJson('task', taskGrp, 'user')
    },

    getNewRoleSec() {
        let useSec = {
            id: 1002,               // 角色编号
            order: -1,              // 站位排序
            equips: [1, 0, 0, 0],     // 装备等级
            hand: 0,                 // 选择装备
        }

        let team = he.local.getJson('team', 'user')
        team.push(useSec)
        he.local.setJson('team', team, 'user')
        this.team = team
        this.info = useSec
        this.initPageView(1)
        // this.lookAd.active = false
    },

    initPageView(index) {
        // this.teamInfo = he.local.getJson('team', 'user')
        let lockList = he.db.getTable('Lock')
        let roleGrp = []
        for (let i = 0; i < lockList.length; i++) {
            roleGrp.push(lockList[i].unlock)
        }
        //    = [1001, 1002, 1003, 1004, 1005]                 //he.db.getTable('Role')
        // let grp = []
        // for (let i = 0; i < roleGrp.length; i++) {
        //     this.checkIsinTeam(grp, roleGrp[i])
        // }
        // console.log(grp)
        // this.pageView_node.getComponent('equipPageView').grpInit(this.teamInfo, index, this.equopIndex)
        this.pageView_node.getComponent('equipPageView').grpInit(roleGrp, index, this.index)
    },

    checkIsinTeam(grp, num) {
        if (num >= 1006) {
            return
        }
        if (grp && grp.length > 0) {
            let isHave = false
            for (let i = 0; i < grp.length; i++) {
                if (grp[i] == num) {
                    isHave = true
                    break
                }
            }
            if (!isHave) {
                grp.push(num)
            }
        } else {
            grp.push(num)
        }

    },

    //4个装备栏中选择了其中一个
    btnStateChange(info, index) {
        this.index = index
        this.info = info
        //所选装备栏装备等级为0级的情况
        if (this.info.equips[this.index] == 0) {
            this.setEquipBtn_node.active = true
            this.setEquipBtn_lab.string = '未解锁'
            this.setEquipBtn_node.getComponent(cc.Button).interactable = false
            this.setEquipBtn_node.color = cc.Color.GRAY
            this.lvupBtn_sp.spriteFrame = he.load.get('equipPage', cc.SpriteAtlas, 'plist').getSpriteFrame("text_jiesuo")
        } else {

            this.setEquipBtn_node.active = true
            //框
            //按钮状态更新
            if (info.hand == index) {
                this.setEquipBtn_lab.string = '已装备'
                this.setEquipBtn_node.getComponent(cc.Button).interactable = false
                this.setEquipBtn_node.color = cc.Color.GRAY
            } else {
                this.equopIndex = index
                this.setEquipBtn_node.color = cc.Color.WHITE
                this.setEquipBtn_node.getComponent(cc.Button).interactable = true
                this.setEquipBtn_lab.string = '设置装备'
            }
            this.lvupBtn_sp.spriteFrame = he.load.get('equipPage', cc.SpriteAtlas, 'plist').getSpriteFrame("text_shengji")
        }
        let equipContent = this.pageView_content.children[1].getChildByName('equipGrp')
        // this.showPanal()
        for (let i = 0; i < equipContent.children.length; i++) {
            equipContent.children[i].getComponent('equipItem').hideLight()
        }
        equipContent.children[index].getComponent('equipItem').showLight()

    },
    //设置装备
    setEquip() {
        let index = null
        //待改
        // let team = he.local.getJson('team', 'user')
        // let team=roleTeam
        for (let j = 0; j < this.team.length; j++) {
            if (this.team[j].id == this.info.id) {
                index = j
                this.team[j].hand = this.index
                break
            }
        }
        // roleTeam=team
        he.local.setJson('team', this.team, 'user')
        gg.eventManager.emit('equipItem', { code: UI_Listen.EQUIPITEM_INFOUPDATE, info: this.team[index] })
        // this.initPageView(index)
        // this.setEquipBtn_node.active = true
        // this.setEquipBtn_lab.string = '已装备'
        // this.setEquipBtn_node.getComponent(cc.Button).interactable = false
        // this.setEquipBtn_node.color = cc.Color.GRAY
    },

    //升级按钮
    lvUpServer() {
        if (this.canLvup) {
            let lv = this.info.equips[this.index] + 1
            let equipInfo = he.db.getDataByArgs("Equip", { equip: this.index, level: lv })
            let roleNeed = he.db.getDataByArgs("Role", { roleId: this.info.id, level: lv })
            let grp = `${equipInfo.cost}#${roleNeed.cost}`
            gg.data.checkItemStr(grp, true)
            let equipLv = this.info.equips[this.index]
            if (equipLv < 10) {
                equipLv += 1
            }

            this.info.equips[this.index] = equipLv
            // let team = he.local.getJson('team', 'user')
            // let team = roleTeam
            let index = null
            for (let j = 0; j < this.team.length; j++) {
                if (this.team[j].id == this.info.id) {
                    index = j
                    this.team[j] = this.info
                    break
                }
            }
            he.local.setJson('team', this.team, 'user')
            let taskGrp = he.local.getJson('task', 'user')
            if (taskGrp && taskGrp.length > 0) {
                for (let i = 0; i < taskGrp.length; i++) {
                    if (taskGrp[i].type == 9004 && (taskGrp[i].num < taskGrp[i].need)) {
                        taskGrp[i].num += 1
                        break
                    }
                }
                he.local.setJson('task', taskGrp, 'user')
            }
            // this.showPanal()
            this.initPageView(index)
            gg.eventManager.emit('equipItem', { code: UI_Listen.EQUIPITEM_INFOUPDATE, info: this.team[index] })
        } else {
            gg.uiManager.addTip('素材不足')
        }
    },


    //更新升级所需素材信息
    showPanal() {
        this.lvupPanal_node.active = true
        this.detail_btn.active = true
        let lv = this.info.equips[this.index] + 1
        if (lv <= 10) {
            let equipInfo = he.db.getDataByArgs("Equip", { equip: this.index, level: lv })
            let roleNeed = he.db.getDataByArgs("Role", { roleId: this.info.id, level: lv })
            let grp = `${equipInfo.cost}#${roleNeed.cost}`
            this.canLvup = gg.data.checkItemStr(grp, false)
            // if(this.canLvup){
            this.mergeGrp.active = true
            this.del_node.active = false
            // this.merGrpInit()
            // }
        } else {
            this.showDelInfo('该装备已升至满级')
        }

    },
    //合成素材栏 初始化
    merGrpInit() {
        let lv = this.info.equips[this.index] + 1
        let costGrp = he.db.getDataByArgs("Equip", { equip: this.index, level: lv })
        let roleNeed = he.db.getDataByArgs("Role", { roleId: this.info.id, level: lv })
        let grp = `${costGrp.cost}#${roleNeed.cost}`.split('#')
        for (let j = 0; j < this.mergeGrp.children.length; j++) {
            this.mergeGrp.children[j].active = false
        }
        for (let i = 0; i < grp.length; i++) {
            // let xx = gg.data.checkItem(grp[i])
            let infoGrp = grp[i].split('_')
            this.mergeGrp.children[i].active = true
            let itemScript = this.mergeGrp.children[i].getComponent('bagItem')
            // let item_id = parseInt(infoGrp[0],SHOW_ITEM_TYPE.BY_CHECK)
            itemScript.initInfo(grp[i], SHOW_ITEM_TYPE.BY_CHECK)
            itemScript.setNum(infoGrp[1])
        }
    },

    //隐藏合成素材栏
    hidePanal() {
        this.lvupPanal_node.active = false
        this.lvUpBtn_node.active = false
    },
    //未解锁状态更新
    lockState() {
        this.showTitleNum(this.pageIndex)
        if (this.info == null && this.pageIndex != 1002) {
            // this.lookAd.active = false
            this.del_node.active = true
            // let name = `jiesuowenzi${(this.pageIndex - 1001)}`
            // this.del_node.getComponent(cc.Sprite).spriteFrame = he.load.get('equipPage', cc.SpriteAtlas, 'plist').getSpriteFrame(name)

        } else if (this.info == null && this.pageIndex == 1002) {
            this.del_node.active = true
            // this.lookAd.active = true
        }
    },
    //展示提示数字
    showTitleNum(num) {
        let lock = he.db.getTable('Lock')
        let needNum
        if (lock && lock.length > 0) {
            for (let i = 0; i < lock.length; i++) {
                if (num == parseInt(lock[i].unlock)) {
                    needNum = lock[i].pass
                    break
                }
            }
            let numList = ('' + needNum).split('')
            this.num1_sp.node.active = false
            this.num2_sp.node.active = false
            for (let j = 0; j < numList.length; j++) {
                if (j == 0) {
                    this.num1_sp.node.active = true
                    this.num1_sp.spriteFrame = he.load.get('numTitle', cc.SpriteAtlas, 'plist').getSpriteFrame(`${numList[j]}`)
                }
                if (j == 1) {
                    this.num2_sp.node.active = true
                    this.num2_sp.spriteFrame = he.load.get('numTitle', cc.SpriteAtlas, 'plist').getSpriteFrame(`${numList[j]}`)
                }
            }
        }
    },

    unlockState() {
        // this.lookAd.active = false
        this.del_node.active = false
    },

    //展示提示信息
    showDelInfo(str) {
        this.mergeGrp.active = false
        this.del_node.active = true
    },


});
